<?php
declare(strict_types=1);
namespace Service\EsService;
use Service\BaseService;
use Service\Code\Normal;
use App\Amqp\Producer\StoreESMessageProducer;
use App\Amqp\Producer\ChannelESMessageProducer;
use Hyperf\Amqp\Producer;
use Hyperf\Utils\ApplicationContext;

/**
 * ES发布消息中心
 */
class EsPublishMsgService extends BaseService
{
    /**
     * 店铺商品ES消息服务数据同步
     * @param array $msg
     */
    public function storeESMessageProducer(array $data)
    {
        try {
            $message = new StoreESMessageProducer($data);
            $producer = ApplicationContext::getContainer()->get(Producer::class);
            $producer->produce($message,true);
            return Normal::returnCode(Normal::SUC,"发布成功");
        } catch ( \Throwable $th ) {
            return Normal::returnCode(Normal::FAIL,"发布消息队列失败【{$th->getMessage()}】");
        }
    }
    
    /**
     * 渠道商品ES消息服务数据同步
     * @param array $msg
     */
    public function channelESMessageProducer(array $data)
    {
        try {
            $message = new ChannelESMessageProducer($data);
            $producer = ApplicationContext::getContainer()->get(Producer::class);
            $producer->produce($message,true);
            return Normal::returnCode(Normal::SUC,"发布成功");
        } catch ( \Throwable $th ) {
            return Normal::returnCode(Normal::FAIL,"发布消息队列失败【{$th->getMessage()}】");
        }
    }
}